﻿<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<script type="text/javascript">
	var sparepart = {
		gridId : "sparepartDiscardDetailGrid",
		saveUrl : "sparepart/sparepartChangeDetail/save"
	};
</script>

<script type="text/javascript" src="js/widget/sparepart.js"></script>

<form:form id="sparepartDiscardForm" commandName="model"
	cssClass="validate" action="sparepart/sparepartDiscard/save">
	<form:hidden path="id" />
	<isperp:processProcesser processId="${model.processId }"></isperp:processProcesser>
	<table class=" form-table">
		<tr>
			<td class="td1">报废编号：</td>
			<td class="td2"><form:input path="code" disabled="true" /><span>
					(自动生成)</span>
			</td>
			<td class="td1">报废日期：</td>
			<td class="td2"><form:input type="date" path="discardDate"
					cssClass="required" />
			</td>
		</tr>
		<tr>
			<td class="td1">申请人：</td>
			<td class="td2"><form:hidden path="applyManId" /> <isperp:departmentUser
					id="applyManName" displayValue="${model.applyManName }"
					afterSelected="afterSelected(row);" displayValueCssClass="required"
					name="applyManName" valueControlId="applyManId"></isperp:departmentUser>
			</td>
			<td class="td1">项目：</td>
			<td class="td2"><form:select path="projectId"
					items="${projects }" itemLabel="name" itemValue="id"
					cssClass="required"></form:select>
			</td>
		</tr>
		<tr>
			<td class="td1">描述：</td>
			<td class="td2" colspan="3"><form:textarea path="memo"
					cssClass="required" /> </textarea></td>
		</tr>
		<tr>
			<td class="td1">填表人：</td>
			<td class="td2"><label>${model.creatorName }</label>
			</td>
		</tr>
		<tr>
			<td class="td1">附件：</td>
			<td class="td2" colspan="3"><isperp:uploader
					sourceId="${model.id }" id="sptFiles"></isperp:uploader>
			</td>
		</tr>
	</table>
</form:form>
<isperp:grid
		url="sparepart/sparepartIn/listSparepartCi?sparepartId=${model.id }"
		gridId="sparepartInCiDetailGrid" showPager="false"
		showSearchbar="false" cusDialogSize="big"
		cusDeleteUrl="sparepart/sparepartRelation/deleteByCiId?typeKey=sparepartDiscard"
		cusEditUrl="configuration/ci/edit?ty=sparepartDiscard"
	    cusFormatterActions="true">
		<jsp:attribute name="toolbar">
		<isperp:toolbar id="iconToolbar">
		   <div style="float:left;" class="header">
					<h3>报废设备清单(备注：状态默认为报废，责任人为当前登录者，单击编辑可修改其他资产信息)</h3>
				</div>
			<%-- <isperp:button text="选择报废资产" icon="icon-plus" onclick="choseCi();"></isperp:button> --%>
		</isperp:toolbar>
		</jsp:attribute>

		<jsp:body>
		<isperp:column name="id" title="id" hidden="true"></isperp:column>
		<isperp:column name="code" title="编号" width="150">
		</isperp:column>
		<isperp:column name="name" title="名称" width="100">
		</isperp:column>
		<isperp:column name="confCategoryName" title="分类" width="120">   
		</isperp:column>
		<isperp:column name="statusTemp" title="状态" width="120"
				>   
		</isperp:column>
		<isperp:column name="locationName" title="位置" width="120">   
		</isperp:column>
		<isperp:column name="useStaffNameTemp" title="责任人" width="120">   
		</isperp:column>
	</jsp:body>
	</isperp:grid>
<isperp:listSelector id="ciRelateSelector" displayValueCssClass="hidden"
	showClearBtn="false" selectorCssClass="hidden" reloadOnOpen="true"
	url="configuration/ci/listSparepartCiByCusUserName?sparepartId=${model.id }"
	afterSelected="gird_afterSelected(rows)" multiselect="true">
	<isperp:column name="id" title="id" hidden="true"></isperp:column>
	<isperp:column name="code" title="编号" width="80">
	</isperp:column>
	<isperp:column name="name" title="名称" width="100">
	</isperp:column>
	<isperp:column name="status" title="状态" width="60">
	</isperp:column>
	<isperp:column name="useStaffName" title="责任人" width="80">
	</isperp:column>
	<isperp:column name="confCategoryName" title="类别" width="80">
	</isperp:column>
</isperp:listSelector>



<div class="header">
	<h3>关联流程</h3>
</div>

<isperp:processRelation businessKey="${model.id }" readonly="false"
		processKey="sparepartDiscardProcess" projectIdControl="projectId"
		showTotalControl="relationProcessCount"></isperp:processRelation>

<isperp:buttonList>
	<isperp:processButtons processKey="sparepartDiscardProcess"
		processId="${model.processId }" businessKey="${model.id }"
		formId="sparepartDiscardForm"></isperp:processButtons>
</isperp:buttonList>
<script type="text/javascript">
function choseCi() {
		$("#ciRelateSelector").click();
	}
	function gird_afterSelected(rows) {
		if (rows.length < 1) {
			isperp.alert("没有数据被选择！")
			return;
		}
		var ids = "";
		for ( var i = 0; i < rows.length; i++) {
			if (i == 0) {
				ids = rows[0].id;
			} else {
				ids += "," + rows[i].id;
			}
		}
		$.ajax({
			url : "sparepart/sparepartRelation/saveRelation",
			data : {
				sparepartId : '${model.id}',
				ciId : ids,
				typeKey : 'sparepartDiscard'
			},
			success : function(data) {
				sparepartInCiDetailGrid.search();
			},
			error : function(data) {
				isperp.alert(data)
			}
		});

	}
	function afterSelected(row) {
		$.getJSON("project/member/listProjectByUsername?username=" + row[0], function(data) {

			$("#projectId").empty();
			if (data[0]) {
				$(data).each(function(index, item) {
					$("#projectId").append('<option value="'+item.id+'">' + item.name + '</option>');
				});
			}
			$("#projectId").trigger("chosen:updated");
		});
	}
</script>